package com.hc.acoustics.util

import android.text.Editable
import android.text.TextWatcher
import android.view.Gravity
import android.widget.EditText
import com.hc.acoustics.R
import com.yc.yclibx.comment.YcEmpty
import com.yc.yclibx.comment.YcResources

/**
 *
 */
object UiHelperUtil {
    fun getDoublea(edit: EditText) {
        edit.toString()
    }

    fun editChange(edt: EditText, isAble: Boolean) {
        if (isAble) {
            edt.setBackgroundResource(R.drawable.shape_blue_round)
            edt.setTextColor(YcResources.getColor(R.color.textColor1))
            edt.gravity = Gravity.CENTER
            edt.isFocusable = true
            edt.isFocusableInTouchMode = true
            if ("-" == edt.text.toString()) {
                edt.setText("")
            }
        } else {
            edt.setBackgroundResource(R.color.colorTrance)
            edt.setTextColor(YcResources.getColor(R.color.colorRed))
            edt.gravity = Gravity.RIGHT
            edt.isFocusable = false
            edt.isFocusableInTouchMode = false
            if (YcEmpty.isEmpty(edt.text.toString())) {
                edt.setText("-")
            }
        }
    }

    fun editChangeCall(edt: EditText, call: TextChangeCall) {
        edt.addTextChangedListener(object : TextWatcher {
            override fun afterTextChanged(p0: Editable?) {
            }

            override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
                call.call(p0.toString())
            }
        })
    }
}